<?php
// +----------------------------------------------------------------------
// | 有理想的地方，地狱都是天堂。
// +----------------------------------------------------------------------
// | Copyright @ df81.com 版权所有
// +----------------------------------------------------------------------
// | 作者: 南国老符 邮箱：1062129401@qq.com
// +----------------------------------------------------------------------

namespace app\apple\controller;
use app\api\model\v1\Common as apiCommonModel;
use think\facade\Db;
use think\facade\View;

class Site extends Base{
    // 标签列表
    public function tags(){
        $urlroute = input('urlroute'); $page = input('page');
        //若urlroute为空，则301重定向
    	if(empty($urlroute)){
			header('HTTP/1.1 301 Moved Permanently');//发出301头部
            header('Location: '.request()->domain().the_list_url('news'));
		}
		//关键词
        $keywordWhere[] = ['urlroute','=',$urlroute]; $keywordWhere[] = ['lang','=',$this->lang];
        $keywordRs = Db::name('keyword')->where($keywordWhere)->field('keyword,urlroute')->find();

        //若关键词为空，则301重定向
    	if(empty($keywordRs)){
			header('HTTP/1.1 301 Moved Permanently');//发出301头部
            header('Location: '.request()->domain().the_list_url('news'));
		}

        //关键词
        $tagCloud = apiCommonModel::tagCloud('news','keyword,urlroute',$this->lang,55);
        View::assign('tagCloud',$tagCloud);
        View::assign('kwRs',$keywordRs);

        //内页banner
        $pageWhere[] = ['signid','=',1]; $pageWhere[] = ['lang','=',$this->lang];
        $pageWhere[] = ['position','=','about']; $pageWhere[] = ['att_type','=','banner'];
        $pageBanner = Db::name('ad')->where($pageWhere)->value('thumb');
        $pageBanner = !empty($pageBanner) ? $pageBanner : '';
        View::assign('page_banner',$pageBanner);

		//列表
		$order = ["news.addtime"=>'desc'];
		$rs = apiCommonModel::tagList('news','*',$this->lang,$urlroute,$keywordRs['keyword'],10,$order);
		View::assign('list',$rs);
		View::assign('total',$rs->total());
		View::assign('last_page',$rs->lastPage());

        return view();
    }
    
    // 标签地图
    public function map(){
        //取出字母
        $kwArr = array();
        $keywordList = Db::name('keyword')->where('lang','=',$this->lang)->field('urlroute')->select();
        foreach ($keywordList as $kwRs) {
        	$first = substr($kwRs['urlroute'],0,1);
        	if(!in_array($first, $kwArr)){
        		$kwArr[] = $first;
        	}
        }
        sort($kwArr);
        View::assign('letterList',$kwArr);

    	//标签地图
        $tagMap = apiCommonModel::sitemap('news','keyword,urlroute',$this->lang,$kwArr);
        View::assign('tagMap',$tagMap);

        //内页banner
        $pageWhere[] = ['signid','=',1]; $pageWhere[] = ['lang','=',$this->lang];
        $pageWhere[] = ['position','=','about']; $pageWhere[] = ['att_type','=','banner'];
        $pageBanner = Db::name('ad')->where($pageWhere)->value('thumb');
        $pageBanner = !empty($pageBanner) ? $pageBanner : '';
        View::assign('page_banner',$pageBanner);

        return view();
    }
    
	// 本站协议
    public function agreement(){
        return view();
    }
}